﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class webadmin_pages_khoadaotao_frm : System.Web.UI.Page
{

    private Common _common;
    public static string _muc_chon = "0";
    public string act = "";
    public string mess = "";
    public string messnotID = "";
    protected void btn_save_Click(object sender, EventArgs e)
    {
        SqlParameter[] sqlparam = new SqlParameter[0x11];
        sqlparam[1] = new SqlParameter("@ten_khoa_dt", this.txt_kh_ten.Text);
        sqlparam[2] = new SqlParameter("@ma_nganh_dt", this.drop_nganhnghe.SelectedValue);
        sqlparam[3] = new SqlParameter("@ma_trinh_do_dt", this.drop_kh_trinhdo.SelectedValue);
        sqlparam[4] = new SqlParameter("@ma_co_so_dt", this.Session["ma_co_so"]);
        sqlparam[5] = new SqlParameter("@ma_hinh_thuc_dt", this.drop_kh_hinhthuc.SelectedValue);
        sqlparam[6] = new SqlParameter("@ngay_nhan_ho_so", this.txt_ngaynhan.Text);
        sqlparam[7] = new SqlParameter("@ngay_dong_ho_so", this.txt_ngayhethan.Text);
        sqlparam[8] = new SqlParameter("@ngay_khai_giang", this.txt_ngaykhaigiang.Text);
        sqlparam[9] = new SqlParameter("@thoi_gian_hoc", this.txt_kh_thoigian.Text);
        sqlparam[10] = new SqlParameter("@hoc_phi", this.txt_kh_hocphi.Text);
        sqlparam[11] = new SqlParameter("@so_hoc_vien", this.txt_kh_soluong_dt.Text);
        sqlparam[12] = new SqlParameter("@so_duoc_gtvl", this.txt_kh_soluong_gt.Text);
        sqlparam[13] = new SqlParameter("@mo_ta", this.txt_kh_mota.Text);
        sqlparam[14] = new SqlParameter("@chi_tiet_khac", this.txt_kh_thongtinkhac.Text);
        sqlparam[15] = new SqlParameter("@ma_nguoi_dung", this.Session["UserID"]);
        sqlparam[0x10] = new SqlParameter("@kich_hoat", false);
        if (string.IsNullOrEmpty(base.Request.Params["id"]))
        {
            try
            {
                string str = Convert.ToInt32(this._common.execScalar("select (max(ma_khoa_dt) +1) as lastid from DaoTao_khoa_dao_tao")).ToString("D4");
                sqlparam[0] = new SqlParameter("@ma_khoa_dt", str);
            }
            catch
            {
                sqlparam[0] = new SqlParameter("@ma_khoa_dt", "0001");
            }
            if (this._common.ExeceuteByStoreProcedure(sqlparam, "KHOADAOTAO_ADD") > 0)
            {
                base.Response.Redirect("khoadaotao_list.aspx?m=1");
            }
        }
        else
        {
            sqlparam[0] = new SqlParameter("@ma_khoa_dt", this.txtMa.Text);
            if (this._common.ExeceuteByStoreProcedure(sqlparam, "KHOADAOTAO_UPDATE") > 0)
            {
                base.Response.Redirect("khoadaotao_list.aspx?m=1");
            }
        }
    }

    private void LoadHinhthuc()
    {
        DataSet set = this._common.ExeceuteDataset("select * from DaoTao_hinh_thuc_dao_tao");
        this.drop_kh_hinhthuc.DataSource = set;
        this.drop_kh_hinhthuc.DataTextField = "ten_hinh_thuc_dt";
        this.drop_kh_hinhthuc.DataValueField = "ma_hinh_thuc_dt";
        this.drop_kh_hinhthuc.DataBind();
    }

    private void LoadInfo(string id)
    {
        DataSet set = this._common.ExeceuteDataset("select * from DaoTao_khoa_dao_tao where ma_khoa_dt = '" + id + "'");
        if (set.Tables[0].Rows.Count > 0)
        {
            this.txt_kh_hocphi.Text = set.Tables[0].Rows[0]["hoc_phi"].ToString();
            this.txt_kh_mota.Text = set.Tables[0].Rows[0]["mo_ta"].ToString();
            this.txt_kh_soluong_dt.Text = set.Tables[0].Rows[0]["so_hoc_vien"].ToString();
            this.txt_kh_soluong_gt.Text = set.Tables[0].Rows[0]["so_duoc_gtvl"].ToString();
            this.txt_kh_ten.Text = set.Tables[0].Rows[0]["ten_khoa_dt"].ToString();
            this.txt_kh_thoigian.Text = set.Tables[0].Rows[0]["thoi_gian_hoc"].ToString();
            this.txt_kh_thongtinkhac.Text = set.Tables[0].Rows[0]["chi_tiet_khac"].ToString();
            this.txt_ngaynhan.Text = set.Tables[0].Rows[0]["ngay_nhan_ho_so"].ToString();
            this.txt_ngayhethan.Text = set.Tables[0].Rows[0]["ngay_dong_ho_so"].ToString();
            this.txt_ngaykhaigiang.Text = set.Tables[0].Rows[0]["ngay_khai_giang"].ToString();
            this.drop_kh_hinhthuc.Items.FindByValue(set.Tables[0].Rows[0]["ma_hinh_thuc_dt"].ToString()).Selected = true;
            this.drop_kh_trinhdo.Items.FindByValue(set.Tables[0].Rows[0]["ma_trinh_do_dt"].ToString()).Selected = true;
            this.drop_nganhnghe.Items.FindByValue(set.Tables[0].Rows[0]["ma_nganh_dt"].ToString()).Selected = true;
        }
    }

    private void LoadNganhkinhdoanh(string nn)
    {
        string str = "";
        string[] strArray = nn.Split(new char[] { ',' });
        for (int i = 0; i < strArray.Length; i++)
        {
            if (i < (strArray.Length - 1))
            {
                str = str + "'" + strArray[i] + "',";
            }
            else
            {
                str = str + "'" + strArray[i] + "'";
            }
        }
        DataSet set = this._common.ExeceuteDataset("select * from DanhMuc_nganh_kinh_doanh where ma_nganh_kd IN (" + str + ")");
        this.drop_nganhnghe.DataSource = set;
        this.drop_nganhnghe.DataTextField = "ten_nganh_kd";
        this.drop_nganhnghe.DataValueField = "ma_nganh_kd";
        this.drop_nganhnghe.DataBind();
    }

    private void LoadTrinhdodaotao()
    {
        DataSet set = this._common.ExeceuteDataset("select * from DaoTao_trinh_do_dao_tao");
        this.drop_kh_trinhdo.DataSource = set;
        this.drop_kh_trinhdo.DataTextField = "ten_trinh_do_dt";
        this.drop_kh_trinhdo.DataValueField = "ma_trinh_do_dt";
        this.drop_kh_trinhdo.DataBind();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            this._common = new Common();
            if (!base.IsPostBack && (this.Session["ma_co_so"] != null))
            {
                this.LoadHinhthuc();
                this.LoadTrinhdodaotao();
                string nn = this._common.execScalar("select nganh_dao_tao from DaoTao_co_so_dao_tao where ma_co_so_dt = '" + this.Session["ma_co_so"] + "'");
                this.LoadNganhkinhdoanh(nn);
                if (!string.IsNullOrEmpty(base.Request.Params["id"]))
                {
                    string str2 = base.Request.Params["id"].ToString();
                    this.txtMa.Text = this._common.TextFormat(this._common.TextFormat(str2));
                    this.LoadInfo(str2);
                }
            }
        }
        catch (Exception exception)
        {
            this.mess = "Lỗi hệ thống - " + exception.Message + exception.StackTrace;
        }
    }
}
